package com.zretc.service.impl;

import com.zretc.dao.HouseManagerMapper;
import com.zretc.entity.House;
import com.zretc.entity.HouseManager;
import com.zretc.entity.Track;
import com.zretc.service.HouseManagerService;
import com.zretc.util.Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class HouseManagerServiceImpl implements HouseManagerService {
    @Autowired
    private HouseManagerMapper houseManagerMapper;

    @Override
    public int houseManagerRegiseter(HouseManager houseManager) {
        return houseManagerMapper.inseretHouseManager(houseManager);
    }

    @Override
    public HouseManager login(String houseManagerName, String houseManagerPsw) {
        return houseManagerMapper.findByHouseManagerNameAndHouseManagerPsw( houseManagerName, houseManagerPsw);
    }

    @Override
    public List<String> getHouseId() {
        return houseManagerMapper.findHouse();
    }

    @Override
    public int updateHoseInfo(String houseId ,String houseName, Double houseLimit) {
        return houseManagerMapper.updateHose(houseId,houseName,houseLimit);
    }

    @Override
    public int deleteByHouseId(String houseId) {
        return houseManagerMapper.deleteHouse(houseId);
    }


    @Override
    public int houseManagerAddHouse(House house) {
        return houseManagerMapper.insertHouse(house);
    }

    @Override
    public List<House> getAllHouseList() {
        return houseManagerMapper.findAllHouse();
    }

    @Override
    public House getByHouseList(String houseId) {
        return houseManagerMapper.findByhouseId(houseId);
    }

    @Override
    public List<String> getAddressIdList() {
        return houseManagerMapper.findAddressId();
    }

    @Override
    public List<Track> getEntityAddDeilveryList(String opCode) {
        return houseManagerMapper.findEntryInfo(opCode);
    }

    @Override
    public HouseManager findHouseManagerById(String houseManagerId) {

        return houseManagerMapper.selectHouseManagerById(houseManagerId);
    }

    @Override
    public boolean updateHouseManagerById(Map<String, Object> map) {

        String oldHouseManagerPsw = (String) map.get("houseManagerPsw");

        String houseManagerPsw = Util.getMd5(oldHouseManagerPsw);

        map.put("houseManagerPsw",houseManagerPsw);


        int i = houseManagerMapper.updateHouseManagerById(map);

        return i == 1 ? true : false;
    }

}
